﻿using System;
using System.Collections.ObjectModel;
using System.Windows.Media.Imaging;
using KlavoNotifications.Fetch;
using Microsoft.Practices.Prism.ViewModel;

namespace KlavoNotifications.ViewModels.Tray
{
    public class TrayItemViewModel : NotificationObject
    {
        private int _seconds;

        public TrayItemViewModel()
        {
            Players = new ObservableCollection<TrayPlayerViewModel>();
        }

        public ObservableCollection<TrayPlayerViewModel> Players { get; set; }

        public string Voc { get; set; }
        public int PlayersCount { get; set; }
        public string Url { get; set; }

        public bool IsStarted { get; set; }
        public bool IsCompetition { get; set; }
        public GameType GameType { get; set; }

        public int Seconds
        {
            get { return _seconds; }
            set
            {
                _seconds = value;
                RaisePropertyChanged(() => Seconds);
                RaisePropertyChanged(() => Time);
                RaisePropertyChanged(() => Image);
                RaisePropertyChanged(() => IsEnabled);
            }
        }

        public string Time
        {
            get
            {
                TimeSpan ts = new TimeSpan(0, 0, 0, Seconds);

                return String.Format("{0:00}:{1:00}", ts.Minutes, ts.Seconds);
            }
        }

        public bool IsEnabled
        {
            get { return Seconds > 5; }
        }

        public BitmapImage Image
        {
            get
            {
                Uri uriSource;
                if (IsCompetition)
                {
                    if (IsEnabled)
                        uriSource = new Uri(@"/KlavoNotifications;component/Icons/enterChamp.png", UriKind.Relative);
                    else
                        uriSource = new Uri(@"/KlavoNotifications;component/Icons/enterChampDisabled.png", UriKind.Relative);
                }
                else
                {
                    if (IsEnabled)
                        uriSource = new Uri(@"/KlavoNotifications;component/Icons/enter.png", UriKind.Relative);                        
                    else
                        uriSource = new Uri(@"/KlavoNotifications;component/Icons/enterDisabled.png", UriKind.Relative);
                }
                return new BitmapImage(uriSource);
            }
        }
    }
}